package newapp.dob.com.dc_new_app.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import newapp.dob.com.dc_new_app.R;
import newapp.dob.com.dc_new_app.TakeMoneySureActivity;
import newapp.dob.com.dc_new_app.api.bean.OrderListModel;
import newapp.dob.com.dc_new_app.util.DateTime;
import newapp.dob.com.dc_new_app.util.UI;

/**
 * Created by Administrator on 2016/10/17 0017.
 */

public class PayWayAdapter extends ItemAdapter<OrderListModel.DataBean.ListsBean, PayWayAdapter.OrderListViewHolder> {


//    private Context context;
//    private String title = "支付宝";
//    private boolean isFirst = true;

    public PayWayAdapter(Context context) {
        super(context);
//        this.context = context;
    }

//    public void setTitle(String title) {
//        this.title = title;
//    }

    @Override
    public OrderListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new OrderListViewHolder(inflate(R.layout.item_home_order, parent));
    }

    @Override
    public void onBindViewHolder(OrderListViewHolder holder, int position) {
        OrderListModel.DataBean.ListsBean item = getItem(position);
        holder.txtName.setText(item.real_name);
        holder.txtEmail.setText(item.u_alipay);
        holder.txtDate.setText(DateTime.toMDSS(item.create_time * 1000));
        holder.txtUserOrder.setText(item.alipay + "       " + item.notice_sn);

        if (item.is_paid.equals("1")) {
            holder.btnSubmit.setVisibility(View.VISIBLE);
            holder.txtFailed.setVisibility(View.GONE);
            holder.btnSubmit.setBackgroundResource(R.drawable.button_grey);
            holder.btnSubmit.setText("审核成功");
            holder.btnSubmit.setOnClickListener(null);
            holder.txtMoney.setText("实收  " + item.order_money + "元");
//            UI.setTvHtml(holder.txtMoney, R.string.money_, );
            holder.txtMoney.setTextColor(0xFFCACACA);
        } else if (item.is_failed.equals("1")) {
            holder.btnSubmit.setVisibility(View.GONE);
            holder.txtFailed.setVisibility(View.VISIBLE);
            holder.txtFailed.setText("失败原因：" + item.failed_reason);
            holder.txtMoney.setTextColor(0xFFCACACA);
            holder.txtMoney.setText("待支付  " + item.order_money + "元");
//            UI.setTvHtml(holder.txtMoney, R.string.money_, );
        } else {
            holder.btnSubmit.setVisibility(View.VISIBLE);
            holder.btnSubmit.setBackgroundResource(R.drawable.button_red);
            holder.txtFailed.setVisibility(View.GONE);
            holder.btnSubmit.setText("确认收钱");
            holder.txtMoney.setText("待支付  " + item.order_money + "元");
            UI.setTvHtml(holder.txtMoney, R.string.money_, "待支付  ", item.order_money + "元");
            holder.txtMoney.setTextColor(0xFFf61919);
            holder.btnSubmit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(v.getContext(), TakeMoneySureActivity.class);
                    intent.putExtra("data", item);
                    v.getContext().startActivity(intent);
                }
            });
        }

    }

//    public interface OnCheckListener {
//        void onClick(String way, String pay_id, String payment_description, String title);
//    }
//
//    private OnCheckListener onCheckListener;
//
//    public void setShareClickListener(OnCheckListener onCheckListener) {
//        this.onCheckListener = onCheckListener;
//    }

    class OrderListViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_name)
        TextView txtName;
        @BindView(R.id.txt_email)
        TextView txtEmail;
        @BindView(R.id.txt_date)
        TextView txtDate;
        @BindView(R.id.txt_money)
        TextView txtMoney;
        @BindView(R.id.btn_submit)
        TextView btnSubmit;
        @BindView(R.id.txt_user_order)
        TextView txtUserOrder;
        @BindView(R.id.txt_failed)
        TextView txtFailed;

        private OrderListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

    }
}
